namespace QLGT.Models
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class QLGTContext : DbContext
    {
        public QLGTContext()
            : base("name=QLGTContext")
        {
        }

        public virtual DbSet<sysdiagram> sysdiagrams { get; set; }
        public virtual DbSet<tbl_ChucNang> tbl_ChucNang { get; set; }
        public virtual DbSet<tbl_ChucNang_Quyen> tbl_ChucNang_Quyen { get; set; }
        public virtual DbSet<tbl_ChucVu> tbl_ChucVu { get; set; }
        public virtual DbSet<tbl_DaoTao> tbl_DaoTao { get; set; }
        public virtual DbSet<tbl_GiaoTrinh> tbl_GiaoTrinh { get; set; }
        public virtual DbSet<tbl_GiaoTrinh_HeDT> tbl_GiaoTrinh_HeDT { get; set; }
        public virtual DbSet<tbl_GiaoTrinh_Nam> tbl_GiaoTrinh_Nam { get; set; }
        public virtual DbSet<tbl_HeDaoTao> tbl_HeDaoTao { get; set; }
        public virtual DbSet<tbl_HocHam> tbl_HocHam { get; set; }
        public virtual DbSet<tbl_HocVi> tbl_HocVi { get; set; }
        public virtual DbSet<tbl_Khoa> tbl_Khoa { get; set; }
        public virtual DbSet<tbl_MonHoc> tbl_MonHoc { get; set; }
        public virtual DbSet<tbl_Nganh> tbl_Nganh { get; set; }
        public virtual DbSet<tbl_NguoiDung> tbl_NguoiDung { get; set; }
        public virtual DbSet<tbl_NhaXuatBan> tbl_NhaXuatBan { get; set; }
        public virtual DbSet<tbl_Quyen> tbl_Quyen { get; set; }
        public virtual DbSet<tbl_SachBan> tbl_SachBan { get; set; }
        public virtual DbSet<tbl_SachDat> tbl_SachDat { get; set; }
        public virtual DbSet<tbl_TacGia> tbl_TacGia { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<tbl_ChucNang>()
                .HasMany(e => e.tbl_ChucNang_Quyen)
                .WithRequired(e => e.tbl_ChucNang)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_DaoTao>()
                .Property(e => e.MaNganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_GiaoTrinh_HeDT)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_GiaoTrinh_Nam)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_SachBan)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh_HeDT>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh_Nam>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh_Nam>()
                .Property(e => e.Nam)
                .IsFixedLength();

            modelBuilder.Entity<tbl_HeDaoTao>()
                .HasMany(e => e.tbl_GiaoTrinh_HeDT)
                .WithRequired(e => e.tbl_HeDaoTao)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Khoa>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Khoa>()
                .Property(e => e.Khoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Khoa>()
                .HasMany(e => e.tbl_MonHoc)
                .WithRequired(e => e.tbl_Khoa)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_MonHoc>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_MonHoc>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_MonHoc>()
                .HasMany(e => e.tbl_DaoTao)
                .WithRequired(e => e.tbl_MonHoc)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Nganh>()
                .Property(e => e.MaNganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Nganh>()
                .Property(e => e.Nganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Nganh>()
                .HasMany(e => e.tbl_DaoTao)
                .WithRequired(e => e.tbl_Nganh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.TenDangNhap)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.MatKhau)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.Email)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.RandomPass)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.SoDT)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.Fax)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.Email)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .HasMany(e => e.tbl_GiaoTrinh)
                .WithRequired(e => e.tbl_NhaXuatBan)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .HasMany(e => e.tbl_SachDat)
                .WithRequired(e => e.tbl_NhaXuatBan)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Quyen>()
                .HasMany(e => e.tbl_ChucNang_Quyen)
                .WithRequired(e => e.tbl_Quyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Quyen>()
                .HasMany(e => e.tbl_NguoiDung)
                .WithRequired(e => e.tbl_Quyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_SachBan>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_SachBan>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_SachDat>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_TacGia>()
                .HasMany(e => e.tbl_GiaoTrinh)
                .WithRequired(e => e.tbl_TacGia)
                .WillCascadeOnDelete(false);
        }
    }
}
